package com.game.server.message.proto.execute;

import com.comm.ISession;
import com.game.majiang.config.DataManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.server.db.dao.XyClubPremiumOplogDao;
import com.game.server.db.entity.UserInfoData;
import com.game.server.db.entity.XyClubInfo;
import com.game.server.db.entity.XyClubMemberInfo;
import com.game.server.message.proto.in.AbstractXYfindDividendOperationReq;
import com.game.server.message.proto.out.XYclubPremiumOplogStruct;
import com.game.server.message.proto.out.XYfindDividendOperationRsp;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class XYfindDividendOperationReq extends AbstractXYfindDividendOperationReq {

    @Override
    public void Execute(ISession session) {
        LogicClient client = (LogicClient) LogicServer.getInstance().getClient(session.getId());
        if (client != null && client.checkClick(msgcode)) {
            int limit = 20;
            XYfindDividendOperationRsp rsp = new XYfindDividendOperationRsp();
            XyClubInfo clubInfo = DataManager.getInstance().getMapClub().get(this.clubid);
            if (clubInfo != null) {
                XyClubMemberInfo memberInfo = clubInfo.getPlayer().get(this.uid);
                if (memberInfo != null && memberInfo.getDel_type() == 0 && memberInfo.getIsAccessory() == 1) {
                    JSONObject json = XyClubPremiumOplogDao.findDetailPage(limit, this.page, this.clubid, this.uid);
                    rsp.setAllpage(json.getInt("allpage"));
                    rsp.setAllcount(json.getInt("allcount"));
                    rsp.setPage(this.page);
                    JSONArray array = json.getJSONArray("array");
                    XYclubPremiumOplogStruct[] premiumOplogs = new XYclubPremiumOplogStruct[array.size()];
                    int index = 0;
                    for (Object ent : array) {
                        JSONObject object = JSONObject.fromObject(ent);
                        XYclubPremiumOplogStruct premiumOplog = new XYclubPremiumOplogStruct();
                        premiumOplog.setOptime(object.getString("createdate"));
                        premiumOplog.setVal(object.getInt("val"));
                        premiumOplog.setResidueVal(object.getInt("residueVal"));
                        int pid = object.getInt("pid");
                        UserInfoData infoData = DataManager.getInstance().getMapUserData().get(pid);
                        premiumOplog.setPid(pid);
                        premiumOplog.setName(infoData.getName());

                        premiumOplogs[index] = premiumOplog;
                        index++;
                    }
                    rsp.setPremiumOplogs(premiumOplogs);
                }
            }
            client.Send(rsp);
        }
    }

}
